<?php

class viewProfileDocumentsAction extends baseTLUPimAction
{

    public function execute($request)
    {

        $this->attEditPane = false;
        $this->attSeqNO = false;
        $this->attProfileDocumentTypeId = '';
        $this->attComments = '';
        $this->scrollToAttachments = false;

        $empNumber = $request->getParameter('empNumber');
        $this->empNumber = $empNumber;
        $this->screen = EmployeeAttachment::SCREEN_PROFILE_DOCUMENTS;

        if (!$this->IsActionAccessible($empNumber)) {
            $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
        }

        $this->permission = $this->getDataGroupPermissions($this->screen . '_attachment', $this->empNumber);

        if ($this->getUser()->hasFlash('attachmentMessage')) {

            $this->scrollToAttachments = true;

            list($this->attachmentMessageType, $this->attachmentMessage) = $this->getUser()->getFlash('attachmentMessage');

            if ($this->attachmentMessageType == 'warning') {
                $this->attEditPane = true;
                if ($this->getUser()->hasFlash('attachmentComments')) {
                    $this->attComments = $this->getUser()->getFlash('attachmentComments');
                }

                if ($this->getUser()->hasFlash('attachmentProfileDocumentTypeId')) {
                    $this->attProfileDocumentTypeId = $this->getUser()->getFlash('attachmentProfileDocumentTypeId');
                }

                if ($this->getUser()->hasFlash('attachmentSeqNo')) {
                    $tmpNo = $this->getUser()->getFlash('attachmentSeqNo');
                    $tmpNo = trim($tmpNo);
                    if (!empty($tmpNo)) {
                        $this->attSeqNO = $tmpNo;
                    }
                }
            }
        } else {
            $this->attachmentMessageType = '';
            $this->attachmentMessage = '';
        }


        $this->employee = $this->getProfileDocumentService()->getEmployee($this->empNumber);
        $this->attachmentList = $this->getProfileDocumentService()->getEmployeeProfileDocuments($this->empNumber);
        $param = array(
            'empNumber' => $this->empNumber,
            'fullName' => $this->employee->getFullName()
        );
        $this->form = new ProfileDocumentForm(array(), $param, true);
        $this->deleteForm = new ProfileDocumentDeleteForm(array(), array(), true);
    }

}

